﻿
using System.Collections.Generic;
using Test30.Util;

namespace Test30.Engine
{
    public abstract class EnumerableAction : Action
    {
        protected EnumerableAction(NotNull<Entity> entity)
            : base(entity)
        {
        }

        protected override ActionResult OnProcess()
        {
            if (_enumerator == null)
            {
                _enumerator = OnProcessEnumerable().GetEnumerator();
            }

            // done if the enumerator runs out
            if (!_enumerator.MoveNext()) return ActionResult.Done;

            // return the next step
            return _enumerator.Current;
        }

        protected abstract IEnumerable<ActionResult> OnProcessEnumerable();

        private IEnumerator<ActionResult> _enumerator;
    }
}
